import Updater from "./Updater.js";
import Watcher from "./Watcher.js";
import ComputedWatcher from "./ComputedWatcher.js";
export default {
  //v-text指令处理
  text(vm, node, attValue) {
    Updater.text(vm, node, vm.getValue(attValue));

    //计算属性
    if (vm.computed[attValue]) {
      new ComputedWatcher(vm, attValue, function (value) {
        Updater.text(vm, node, value);
      });
    } else {
      //vm.$data的watcher
      new Watcher(vm, attValue, (value) => {
        Updater.text(vm, node, value);
      });
    }
  },

  html(vm, node, attValue) {
    Updater.html(vm, node, vm.getValue(attValue));
    new Watcher(vm, attValue, (value) => {
      Updater.html(vm, node, value);
    });
  },
  //v-model指令处理
  model(vm, node, attValue) {
    Updater.model(vm, node, vm.getValue(attValue));
    new Watcher(vm, attValue, (value) => {
      Updater.model(vm, node, value);
    });
    node.addEventListener("input", () => {
      vm.getValue(attValue) = node.value;
    });
  },
  //事件指令
  on(vm, node, eventName, attValue) {
    const method = vm.$methods[attValue];
    if (!method) return;
    node.addEventListener(eventName, function (event) {
      method.call(vm, event);
    });
  },
};
